package com.jvyou.framework.controller;



import com.jvyou.framework.domain.dto.RoleDto;
import com.jvyou.framework.domain.entity.Role;
import com.jvyou.framework.service.RoleService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import java.util.List;
import com.jvyou.common.annotation.Log;
import com.jvyou.common.core.domain.model.PageResult;
import com.jvyou.common.core.domain.model.Result;
import com.jvyou.common.enums.log.BusinessType;
import com.jvyou.common.enums.result.HttpCodeEnum;


/**
 * 角色信息表(Role)表控制层
 *
 * @author 橘柚
 * @since 2025-05-29 17:25:35
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/role")
public class RoleController  {
    
    private final RoleService roleService;
    
     /**
     * 查询角色信息表列表
     *
     * @param dto 查询参数
     * @return 角色信息表
     */
    @GetMapping("/list")
    @SaCheckPermission("sys:role:list")
    @Log(title = "查询角色信息表列表", businessType = BusinessType.OTHER)
    public Result<List<Role>> list(@ModelAttribute RoleDto dto) {
        return Result.success(roleService.listRole(dto));
    }

     /**
     * 分页查询角色信息表列表
     *
     * @param dto 查询参数
     * @return 角色信息表
     */
    @GetMapping("/page")
    @SaCheckPermission("sys:role:page")
    @Log(title = "分页查询角色信息表列表", businessType = BusinessType.OTHER)
    public Result<PageResult<Role>> page(@ModelAttribute RoleDto dto) {
        return Result.success(roleService.pageRole(dto));
    }

    /**
     * 通过主键查询角色信息表单条
     *
     * @param id 角色信息表主键
     * @return 角色信息表
     */
    @GetMapping("/{id}")
    @Log(title = "通过主键查询角色信息表")
    @SaCheckPermission("sys:role:get")
    public Result<Role> selectOne(@PathVariable Long id) {
        return Result.success(roleService.getById(id));
    }

    /**
     * 新增角色信息表
     *
     * @param role 角色信息表实体对象
     * @return 新增角色信息表结果
     */
    @PostMapping
    @Log(title = "新增角色信息表",  businessType = BusinessType.INSERT)
    @SaCheckPermission("sys:role:insert")
    public Result<Role> insert(@RequestBody Role role) {
        boolean success = roleService.save(role);
        return success ? Result.success(role) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改角色信息表
     *
     * @param role 角色信息表实体对象
     * @return 修改角色信息表结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("sys:role:update")
    @Log(title = "修改角色信息表数据", businessType = BusinessType.UPDATE)
    public Result<Role> updateById(@RequestBody Role role) {
        boolean success = roleService.updateById(role);
        return success ? Result.success(role) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除角色信息表数据
     *
     * @param id 角色信息表主键
     * @return 删除角色信息表结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:role:delete")
    @Log(title = "删除角色信息表",  businessType = BusinessType.DELETE)
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = roleService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

